package com.example.kugouwty.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.kugouwty.R;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TuiJianFragment extends Fragment {

    GridView navigationGrid;
    GridView songListGrid;
    SimpleAdapter navigationGridAdapter;
    SimpleAdapter songListGridAdapter;
    TextView day;
    TextView month;
    TextView week;

    String[] navigationTitle = new String[]{"乐库", "猜你喜欢", "每日推荐", "排行榜", "更多"};
    int[] navigationIcon = new int[]{R.drawable.yueku,
            R.drawable.cainixihuan,
            R.drawable.meirituijian,
            R.drawable.paihangbang,
            R.drawable.gengduo};
    String[] songListTitle = new String[]{"暖心话语：上班中途小确幸",
            "Tropical House|霓虹之夜 盛装一夏！",
            "【古风呈书】以回忆为墨，落款你我",
            "抒情爵士：优雅浪漫的午后微醺独享",
            "欧美民谣：诉说你那点小秘密！",
            "潮流达人必备|炫酷节奏惹人爱"};
    int[] songListImages = new int[]{R.drawable.songlistimage01,
            R.drawable.songlistimage02,
            R.drawable.songlistimage03,
            R.drawable.songlistimage04,
            R.drawable.songlistimage05,
            R.drawable.songlistimage06};
    String[] weekDays = new String[]{"周日", "周一", "周二", "周三", "周四", "周五", "周六"};

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        // 加载推荐页面
        View view = inflater.inflate(R.layout.tuijian_layout, container, false);

        // navigationGrid
        navigationGrid = view.findViewById(R.id.navigationGrid);
        List<Map<String, Object>> navigationList = new ArrayList<>();
        for (int i = 0; i < navigationTitle.length; i++) {
            Map<String, Object> navigationMap = new HashMap<>();
            navigationMap.put("navigationTitle", navigationTitle[i]);
            navigationMap.put("navigationIcon", navigationIcon[i]);
            navigationList.add(navigationMap);
        }
        navigationGridAdapter = new SimpleAdapter(getActivity(), navigationList, R.layout.navigation_layout, new String[]{"navigationTitle", "navigationIcon"}, new int[]{R.id.navigationText01, R.id.navigationIcon01});
        navigationGrid.setAdapter(navigationGridAdapter);

        // songListGrid
        songListGrid = view.findViewById(R.id.songList);
        List<Map<String,Object>> songList = new ArrayList<>();
        for (int i = 0; i < songListTitle.length; i++) {
            Map<String,Object> songListMap = new HashMap<>();
            songListMap.put("songListTitle",songListTitle[i]);
            songListMap.put("songListImages",songListImages[i]);
            songList.add(songListMap);
        }
        songListGridAdapter = new SimpleAdapter(getActivity(),songList,R.layout.songlist_layout,new String[]{"songListTitle","songListImages"},new int[]{R.id.songListText01,R.id.songListImage01});
        songListGrid.setAdapter(songListGridAdapter);

        // 显示当前日期
        day = view.findViewById(R.id.day);
        month = view.findViewById(R.id.month);
        week=view.findViewById(R.id.week);
        Calendar calendar = Calendar.getInstance();
        int dayTime = calendar.get(Calendar.DAY_OF_MONTH);
        int monthTime = calendar.get(Calendar.MONTH);
        day.setText(dayTime+"");
        month.setText((monthTime+1)+"");
        week.setText(weekDays[calendar.get(Calendar.DAY_OF_WEEK)-1]);


        return view;


    }


}
